package UIFree.FX.pageturner
{
	import UIFree.uif_ecomponent;
	
	import flash.display.DisplayObject;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	
	public class pt_heartTurner extends pt_maskTurner
	{
		[Embed(source="images/heart.swf", symbol="heart")]
		[Bindable]
		public static var c_heart: Class;
		public static const heartCount: int = 8;
		
		public function pt_heartTurner(parent:uif_ecomponent, a_transition:Function=null, a_fps:Number=20, a_duration:Number=1500)
		{
			super(parent, a_transition, a_fps, a_duration);
		}
		
		override protected function startFX(): void {
			initHearts();
			endBitmap.filters = [new GlowFilter(0xFFFFFF, 1, 20, 20, 2, 2)];
			super.startFX();
		}
		
		override protected function endFX(): void {
			super.endFX();
			slideMask.removeChilds();
		}
		
		protected function initHearts(): void {
			for (var y:int =0; y<heartCount; y++) {
				for (var x:int =0; x<heartCount; x++) {
					var heart: DisplayObject = new c_heart();
					heart.scaleX = 0;
					heart.scaleY = 0;
					heart.x = endBitmap.width/(heartCount - 1) * x;
					heart.y = endBitmap.height/(heartCount - 1) * y;
					slideMask.addChild(heart);
				}
			}
		} 
		
		override protected function paintMask():void {
			var i: int = 0; 
			for (var y:int =0; y<heartCount; y++)
				for (var x:int =0; x<heartCount; x++) {
					var scale: Number = Math.sin(x / heartCount * Math.PI) + Math.cos(y / heartCount * Math.PI);
					var size: Point = new Point(
						endBitmap.width/heartCount * state * (2.6 + scale), 
						endBitmap.height/heartCount * state * (2.6 + scale)
					);
					var heart: DisplayObject = slideMask.getChildAt(i);
					heart.width = size.x;
					heart.height = size.y;
					i++;
				}
		}
	}
}